﻿using System;
using System.Windows;
using System.Windows.Data;

namespace PhoneInfo
{
    public class stringTosubstr : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string type = value as string;
            if(type==null)
            {
                return "\r\n";
            }
            type = type.Replace("\n", " ");
           
            if (type.Length>25)
            {
                try
                {
                    type = type.Substring(0, 28);
                }
              catch(Exception)
                {
                  
                }

                type += "...";
            }
            else if (type.Length <= 18)
            {
               
                type += "\n";
            }
            else
            {
               
                type += "...";
            }
            return type;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
